package com.pk.platform.business.report.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.pk.platform.business.core.dao.impl.GenericDaoImpl;
import com.pk.platform.business.report.dao.IOperateLogReportDao;
import com.pk.platform.business.report.vo.OperateLogVO;
import com.pk.platform.util.StringConverter;
import com.pk.platform.util.constant.Constant;

public class OperateLogReportDaoImpl extends GenericDaoImpl implements
		IOperateLogReportDao {

	public List<Map<String, Object>> queryOperateLogReport(OperateLogVO olvo) {
		List<Object> param = new ArrayList<Object>();
		String sql = this.getReportSql(olvo, param);
		return this.getSjt().queryForList(sql, param.toArray());
	}
	
	private String getReportSql(OperateLogVO olvo, List<Object> param)
	{
		StringBuffer sql = new StringBuffer();
		sql.append("select t1.*, t2.username, t3.kgName");
		sql.append(" from operate_log t1 ");
		sql.append(" left join p_user t2 on t1.userId = t2.id");
		sql.append(" left join kindergarten t3 on t1.kgId = t3.id where 1 = 1");
		if(StringConverter.isNotNull(olvo.getOperateTimeStart()))
		{
			sql.append(" and t1.operateTime >= ?");
			param.add(olvo.getOperateTimeStart());
		}
		if(StringConverter.isNotNull(olvo.getOperateTimeEnd()))
		{
			sql.append(" and t1.operateTime <= ?");
			param.add(olvo.getOperateTimeEnd() + Constant.LATEST_TIME_OF_DAY);
		}
		sql.append(" order by t3.id, t1.operateTime");
		return sql.toString();
	}

}
